package pres.lnk.learn.designpattern.q_iterator.impl;

import pres.lnk.learn.designpattern.q_iterator.Container;
import pres.lnk.learn.designpattern.q_iterator.Iterator;

/**
 * @Author lnk
 * @Date 2018/5/31
 */
public class NameRepository implements Container {
    private String[] names = new String[]{"张三", "李四", "王五", "赵六"};

    @Override
    public Iterator<String> getIterator() {
        return new NameIterator();
    }

    public class NameIterator implements Iterator<String> {
        private int index = 0;

        @Override
        public boolean hasNext() {
            return index < names.length;
        }

        @Override
        public String next() {
            if (hasNext()) {
                return names[index++];
            }
            return null;
        }
    }
}
